﻿using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using Wpf.Netdisk.Models.BaseModel;
using QueryParameter = Wpf.Netdisk.Models.BaseModel.QueryParameter;

namespace Wpf.Netdisk.Services.Common
{
    public class BaseService<TEntity> : IBaseService<TEntity> where TEntity : class
    {
        private readonly HttpRestClient client;
        private readonly string serviceName;

        public BaseService(HttpRestClient client, string serviceName)
        {
            this.client = client;
            this.serviceName = serviceName;
        }
        public Task<ApiResult> ActiveAsync(AdminActiveListDto adminActiveListDto)
        {
            throw new NotImplementedException();
        }

        public Task<ApiResult<TEntity>> GetInfoByIdAsync(string id)
        {
            throw new NotImplementedException();
        }

        public async Task<PageViewModel> GetListAsync<T>(T dto) where T : QueryParameter
        {
            BaseRequest request = new BaseRequest();
            request.Method = RestSharp.Method.Post;
            request.Route = $"baseadmin/{serviceName}/GetList";
            request.Parameter = dto;
            return await client.ExecutePageViewAsync(request);
        }

        public async Task<ApiResult<TEntity>> SaveAsync(TEntity saveDto)
        {
            BaseRequest request = new BaseRequest();
            request.Method = Method.Post;
            request.Route = $"baseadmin/{serviceName}/Save";
            request.Parameter = saveDto;
            return await client.ExecuteAsync<TEntity>(request);
        }
    }
}
